package io.renren.modules.otherReport.controller;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import io.renren.modules.otherReport.model.OtherFinanceAuditExcelBean;
import io.renren.modules.otherReport.model.OtherFinanceAuditExportExcel;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.modules.otherReport.entity.OtherInfoEntity;
import io.renren.modules.otherReport.service.OtherInfoService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import io.renren.common.utils.R;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


/**
 * 其他社会资源 从其他平台获取的数据
 * 
 * @author wxy
 * @email sharonwang_xy@163.com
 * @date 2018-11-19 09:54:04
 */
@RestController
@RequestMapping("otherReport/otherinfo")
public class OtherInfoController {
	@Autowired
	private OtherInfoService otherInfoService;
	
	/**
	 * 列表
	 */
	@RequestMapping("/list")
	@RequiresPermissions("otherReport:otherinfo:list")
	public R list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);

		List<OtherInfoEntity> otherInfoList = otherInfoService.queryList(query);
		int total = otherInfoService.queryTotal(query);
		
		PageUtils pageUtil = new PageUtils(otherInfoList, total, query.getLimit(), query.getCurrPage());
		
		return R.ok().put("page", pageUtil);
	}


	/**
	 * 财务审核信息列表
	 */
	@RequestMapping("/listReportFinanceAuditInfo")
	@RequiresPermissions("otherReport:otherinfo:listReportFinanceAuditInfo")
	public R listReportFinanceAuditInfo(@RequestParam Map<String, Object> params){
		//查询列表数据
		Query query = new Query(params);

		List<OtherInfoEntity> otherInfoList = otherInfoService.queryListReportFinanceAuditInfo(query);
		int total = otherInfoService.queryTotalReportFinanceAuditInfoNum(query);

		PageUtils pageUtil = new PageUtils(otherInfoList, total, query.getLimit(), query.getCurrPage());

		return R.ok().put("page", pageUtil);
	}
	
	/**
	 * 信息
	 */
	@RequestMapping("/info/{id}")
	@RequiresPermissions("otherReport:otherinfo:info")
	public R info(@PathVariable("id") String id){
		OtherInfoEntity otherInfo = otherInfoService.queryObject(id);
		
		return R.ok().put("otherInfo", otherInfo);
	}
	
	/**
	 * 保存
	 */
	@RequestMapping("/save")
	@RequiresPermissions("otherReport:otherinfo:save")
	public R save(@RequestBody OtherInfoEntity otherInfo){
		otherInfoService.save(otherInfo);
		
		return R.ok();
	}
	
	/**
	 * 修改
	 */
	@RequestMapping("/update")
	@RequiresPermissions("otherReport:otherinfo:update")
	public R update(@RequestBody OtherInfoEntity otherInfo){
		otherInfoService.update(otherInfo);
		
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@RequestMapping("/delete")
	@RequiresPermissions("otherReport:otherinfo:delete")
	public R delete(@RequestBody String[] ids){
		otherInfoService.deleteBatch(ids);
		
		return R.ok();
	}

	/**
	 * 审核
	 */
	@RequestMapping("/otherFinanceAudit/{id}")
	@RequiresPermissions("otherReport:otherinfo:otherFinanceAudit")
	public R reportFinanceAudit(@PathVariable("id") String id){

		OtherInfoEntity otherInfo = otherInfoService.queryObject(id);
		otherInfo.setState("5");
		otherInfoService.update(otherInfo);
		return R.ok();
	}



    /**
     * 导出列表
     */
    @RequestMapping("/exportReportFinanceAudit")
    public void exportReportFinanceAudit(@RequestParam Map<String, Object> params , HttpServletRequest request, HttpServletResponse response){

        Query query = new Query(params);

        List<OtherFinanceAuditExcelBean> list = new ArrayList<>();
        list= otherInfoService.listReportFinanceAuditExcel(query);


        //设置excel列名及宽度
        OtherFinanceAuditExportExcel<OtherFinanceAuditExcelBean> ex = new OtherFinanceAuditExportExcel<>();
        String[] headers = { "姓名", "身份证号","联系方式","银行卡号","上报时间","上报地点","违法车牌","违法地点","行驶方向","行驶车道","违法类型","违法代码","车辆品牌","车辆类型","车辆颜色","车辆型号","状态"};
        int[] columnWidths ={4000,   6000,    5000,    6000,     5000,     8000,    5000,     5000,    5000,     5000,    5000,   5000,    5000,     5000,    5000,    5000,    5000};

        //导出excel
        ex.exportExcel("举报举证信息列表", headers, columnWidths, list, response);

    }

	
}
